* Figure 4
use "./data/publications", clear
createvarspub
keep if year>1999
foreach var of varlist ///
ucoimbra ulisboa uminho unova uporto ucp utad uaveiro ///
uevora ualgarve iscte umadeira ubi uacores bp pfaonly {  
gen top`var'=t`var'*(abs=="4" | abs=="4*" | cnrs=="1" | cnrs=="1e" | cnrs=="1g")
gen tot`var'=t`var'
}
bys article_id: keep if _n==1

collapse (sum) top* tot*
local institut "ucoimbra ulisboa uminho unova uporto ucp utad uaveiro uevora ualgarve iscte umadeira ubi uacores bp pfaonly"
foreach x of local institut {  
gen shr`x'=top`x'/tot`x'*100
}
xpose, clear varname
gen name=substr(_varname,4,.)
tempfile share
preserve
rename v1 share
keep if substr(_varname,1,3)=="shr"
save `share' 
restore
keep if substr(_varname,1,3)=="tot"
merge 1:1 name using `share'
drop _m
rename v1 nart
rename name institution
order inst nart 

***********
replace inst="AAAA" if inst=="pfaonly" 
replace inst="BdP" if inst=="bp"
replace inst="UCP" if inst=="ucp"
replace inst="ISCTE" if inst=="iscte"
replace inst="IST" if inst=="ist"
replace inst="U Açores" if inst=="uacores"
replace inst="U Algarve" if inst=="ualgarve"
replace inst="U Aveiro" if inst=="uaveiro"
replace inst="UBI" if inst=="ubi"
replace inst="U Coimbra" if inst=="ucoimbra"
replace inst="U Évora" if inst=="uevora"
replace inst="U Lisboa" if inst=="ulisboa"
replace inst="U Madeira" if inst=="umadeira"
replace inst="U Minho" if inst=="uminho"
replace inst="U Nova" if inst=="unova"
replace inst="U Porto" if inst=="uporto"
replace inst="UTAD" if inst=="utad"
label var nart "Number of articles"
label var share "Share of quality articles"
sort inst
local yref=share[1]
di "Main Foreign is `yref'"
drop if _n==1
twoway (scatter share nart, xlabel(0(50)650) ///
sort mlabel(institution)  mlabposition(12) ///
yline(`yref')), graphregion(fcolor(white)) ///
legend(region(color(white))) scheme(sj)
graph export ./figures/fig4.pdf, replace
